package com.dt.zbcy.provider.core.handle;

import java.io.Serializable;
/**
 * @Auther: liuwenxiang
 * @Date: 2019/3/31 01:00
 * @Description:
 */


public class DubboResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private static final String SUCCESS_CODE = "0";
    private static final String COMMON_ERROR_CODE = "999999";
    private static final DubboResult<Boolean> SUCCESS;
    private static final DubboResult<Boolean> ERROR;
    private boolean success = true;
    private String message;
    private String code;
    private T content;

    public DubboResult() {
    }

    public static DubboResult<Boolean> buildSuccessResult() {
        return SUCCESS;
    }

    public static DubboResult<Boolean> buildErrorResult() {
        return ERROR;
    }

    public static <T> DubboResult<T> buildSuccessResult(T result) {
        DubboResult dubboResult = new DubboResult();
        dubboResult.setCode("0");
        dubboResult.setContent(result);
        return dubboResult;
    }

    public static <T> DubboResult<T> buildErrorResult(String errorCode, String msg) {
        DubboResult dubboResult = new DubboResult();
        dubboResult.setCode(errorCode);
        dubboResult.setMessage(msg);
        dubboResult.setSuccess(false);
        return dubboResult;
    }

    public boolean isSuccess() {
        return this.success && "0".equals(this.code);
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getContent() {
        return this.content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    static {
        new DubboResult();
        SUCCESS = buildSuccessResult(true);
        new DubboResult();
        ERROR = buildErrorResult("999999", "系统错误");
    }
}

